/**************************************************************************************************
	$Header: /pub/cvsroot/mydns/lib/numlist.c,v 1.3 2002/06/23 06:55:59 bboy Exp $
	numlist.c: Routines to manage a simple list of numbers.

	Copyright (C) 2002  Don Moore <bboy@bboy.net>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at Your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**************************************************************************************************/

#include "mydnsutil.h"


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	NUMLIST_INSERT
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
NUMLIST *
numlist_insert(numlist, num)
	NUMLIST *numlist;
	u_int64_t num;
{
	NUMLIST *l;

	if (!(l = numlist))
	{
		l = (NUMLIST *)xmalloc(sizeof(NUMLIST));
		l->size = 0;
		l->num = (u_int64_t *)NULL;
	}
	l->num = (u_int64_t *)xrealloc(l->num, (l->size + 1) * sizeof(u_int64_t));
	l->num[l->size++] = num;

	return (l);
}
/*--- numlist_insert() --------------------------------------------------------------------------*/


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	NUMLIST_FREE
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void
_numlist_free(numlist)
	NUMLIST **numlist;
{
	if (numlist && *numlist)
	{
		NUMLIST *l = *numlist;

		free(l->num);
		free(l);
		*numlist = (NUMLIST *)NULL;
	}
}
/*--- _numlist_free() ---------------------------------------------------------------------------*/


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	NUMLIST_EXISTS
	If the number specified exists in the list, returns 1, else 0.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int
numlist_exists(numlist, num)
	NUMLIST *numlist;
	u_int64_t num;
{
	register int n;

	if (numlist)
		for (n = 0; n < numlist->size; n++)
			if (numlist->num[n] == num)
				return (1);
	return (0);
}
/*--- numlist_exists() --------------------------------------------------------------------------*/

/* vi:set ts=3: */
